const app = getApp();
Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad: function () {
    this.setData({
    
    })
  },

  bindGetUserInfo: function (e) {
    console.log(e.detail.userInfo)
    wx.getUserInfo({
      success: res => {
        app.globalData.userInfo = res.userInfo

        var code = app.globalData.code;
        var rawData = res.rawData;
        var signature = res.signature;
        var encryptedData = res.encryptedData;
        var iv = res.iv;
        wx.request({
          url: 'https://daka.rzkeji.com/api/auth/wxLogin',
          data: {
            "code": code,
            "raw_data": rawData,
            "signature": signature,
            'iv': iv,
            'encryptedData': encryptedData
          },
          method: "POST",
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            if (res.data.level == "success") {
              console.log(res.data)
              wx.setStorageSync('daka_token', res.data.data);
              wx.navigateTo({
                url: '../detail/detail'
              })
            } else {
              wx.showToast({
                title: res.data.message,
                icon: 'none',
                duration: 2000
              })
            }
          }
        })

        if (this.userInfoReadyCallback) {
          this.userInfoReadyCallback(res)
        }
      }
    })
  }
})